<?php
namespace app\api\controller;
use think\Controller;
use think\Session;
use think\Db;
class Addre extends Controller
{
    
    public function __construct(){
        header('Access-Control-Allow-Origin:*');
        header('Access-Control-Allow-Methods:GET, POST, OPTIONS');
    }
    public function finds() {
        $values=$_POST['values'];
         $idx=$_POST['idx'];
        
         
        if ($idx=="1"){
            if($values=="不限"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->paginate(3);
            }else {
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_des','=',$values)
                ->paginate(3);
            };
            return json($res);
        }elseif ($idx=="2"){
            if ($values=="不限"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->paginate(3);
            }else if ($values=="小于1000元"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_price','<',1000)
                ->paginate(3);
            }elseif ($values=="大于1000元"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')            
                ->where('a.house_price','<',2000)
                ->where('a.house_price','>',1000)
                ->paginate(3);
            }elseif ($values=="大于2000元"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                 ->where('a.house_price','<',3000)
                ->where('a.house_price','>',2000)
                
                ->paginate(3);
            } elseif ($values=="大于3000元"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                 ->where('a.house_price','<',5000)
                ->where('a.house_price','>',3000)
                ->paginate(3);
            }elseif ($values=="大于5000元"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_price','>',"5000")
                ->paginate(3);
            }else {
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->paginate(3);
            };
            return json($res);
        }elseif ($idx=="3"){
           $string = implode(',',$values);
            if ($string=="一室"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_type','like',"%一室%")
                ->whereOr('a.house_type','like',"_一室_")
                ->paginate(3);
            }elseif ($string=="二室"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_type','like',"%二室%")
                ->whereOr('a.house_type','like',"_二室_")
                ->paginate(3);
            }elseif ($string=="三室"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_type','like',"%三室%")
                ->whereOr('a.house_type','like',"_三室_")
                ->paginate(3);
            }elseif ($string=="四室"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_type','like',"%四室%")
                ->whereOr('a.house_type','like',"_四室_")
                ->paginate(3);
            }elseif ($string=="五室"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_type','like',"五室")
                ->whereOr('a.house_type','like',"_五室_")
                ->paginate(3);
            }elseif ($string=="五室以上"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_type','like',"%六室%")
                ->whereOr('a.house_type','like',"%七室%")
                ->paginate(3);
            }else {
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->paginate(3);
            }
            return json($res);
            
            
        }
        
        elseif ($idx=="4"){
            if ($values=="不限"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->paginate(3);
            }elseif ($values=="30平米以下"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_size','<',30)
                ->paginate(3);
            }elseif ($values=="30平米-50平米"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_size','>',30)
                ->where('a.house_size','<',50)
                ->paginate(3);
            }elseif ($values=="50平米-90平米"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_size','>',50)
                ->where('a.house_size','<',90)
                ->paginate(3);
            }elseif ($values=="90平米-150平米"){
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_size','>',90)
                ->where('a.house_size','<',150)
                ->paginate(3);
            }else {
                $res = Db::table("housedetails")->alias("a")
                ->join('houseimg i','a.house_id=i.house_id')
                ->field('a.house_id,a.house_price,a.house_type,a.house_lontiude,a.house_latiude,a.house_size,a.house_direction,a.house_wintype,a.house_des,i.img1,i.img2,i.img3,i.img4,i.img5')
                ->where('a.house_size','>',150)
                ->paginate(3);
            };
            return json($res);
            
        }
        
       
    }
}

